<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>12</title>
</head>

<body>
</body>
<script>
    // 问题描述：设置一段距离的台阶，每次只能走一步或两步。请问正好走完台阶最多需要多少种走法？

    function sum(nums) {
        var s = 0
        for (let i = 0; i < nums.length; i++) {
            s += nums[i]
        }
        return s
    }

    function check(nums) {
        var full = true
        nums.forEach(item => {
            // console.log(item,full)
            if (item < 2) {
                full = false
            }
        })
        return full
    }
    // 二进制
    function jiedi(n) {
        var i = 0
        var count = 0;
        var nums = [1]
        // var answer = []
        while (i <= n) {
            // console.log('testSum',nums)
            // console.log('numLength',nums.length)
            var mLength = nums.length
            if (sum(nums) == n) {
                count += 1
                // answer.push({nums})
                console.log('answer',count,nums)
            }
            // console.log('start',nums, i)
            if (check(nums)) { // 是否全满
               for (let m = 0; m <= mLength; m++) {
                    nums[m] = 1
                }
                i++;
                continue;
            }
            // console.log('end',nums,i)
            if (nums[i] == 1) {
                nums[i] += 1
            } else if (mLength > 1) {
                for (let i2 = i; i2 > 0; i2--) {
                    nums[i2] = 1
                    if (nums[i2 - 1] == 2) {
                        continue
                    } else {
                        nums[i2 - 1] = 2
                        break
                    }

                }
            }
            
        }
        return count

    }

    // console.log(jiedi(1))
</script>

</html>
